package day19.HomeWork;

public class Register {
    public static void main(String[] args) {
        Special special=new Special("特需号");
        Normal normal=new Normal("普通号");
        special.setPriority(10);
        normal.setPriority(5);
        special.start();
        normal.start();
        if(normal.getNum()==10){//当普通号叫到10号时，停止叫普通号，先让特需号看完
            try {
                special.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
class Normal extends Thread{
    private int num=20;

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public Normal(String name) {
        super(name);
    }
    @Override
    public void run(){
        for (int i = 1; i <= 20; i++) {
            System.out.println(Thread.currentThread().getName()+i+"号病人准备看病");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+i+"号病人看好病啦");
        }
    }
}
class Special extends Thread{
    private int num=20;
    public Special(String name) {
        super(name);
    }
    @Override
    public void run(){
        for (int i = 1; i <= 10; i++) {
        System.out.println(Thread.currentThread().getName()+i+"号病人准备看病");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
            System.out.println(Thread.currentThread().getName()+i+"号病人看好病啦");
    }}
}